package com.example.demo.leetcode.classics150;

import java.util.List;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _80完全二叉树的节点个数
 * @description
 * @date 2023/08/03 17:44
 * <p>
 * ******************************************************
 */
public class _80完全二叉树的节点个数 {
    int count = 0;

    public int countNodes(TreeNode root) {
        inOrder(root);
        return count;
    }

    private void inOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        inOrder(root.left);
        count++;
        inOrder(root.right);
    }

   public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
}
